package cn.qvtu.web.config;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 代码生成器
 */
public class MyBatisPlusCodeGenerator {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/blog_system01", "root", "123456")
                // 全局配置
                .globalConfig((scanner, builder) -> builder.author(scanner.apply("请输入作者名称？"))
                        .fileOverride().outputDir("D://"))
// 包配置
                .packageConfig((scanner, builder) -> builder.parent(scanner.apply("请输入包名？")))
                .packageConfig(builder-> builder.entity("domain"))
// 策略配置
                .strategyConfig((scanner, builder) -> builder
                        .addInclude(getTables(scanner.apply("请输入表名，多个英文逗号分隔？所有输入 all")))
                        .addTablePrefix("t_")
                        .controllerBuilder()
                        .enableRestStyle()
                        .enableHyphenStyle()
                        .entityBuilder()
                        .enableLombok()
                        .mapperBuilder().enableMapperAnnotation()
                        .build()).execute();
    }

    // 处理 all 情况
    protected static List<String> getTables(String tables) {
        return "all" .equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
    }

}
